feat(storage): add Object Contexts samples and system tests#2200
feat(storage): add Object Contexts samples and system tests#2200salilg-eng wants to merge 14 commits intoGoogleCloudPlatform:mainfrom
Conversation
|
Here is the summary of changes. You are about to add 3 region tags.
This comment is generated by snippet-bot.
|
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces three new PHP samples for managing Cloud Storage object contexts: get_object_contexts, list_object_contexts, and set_object_contexts. It also includes a comprehensive test case in ObjectsTest.php to verify these functionalities. Feedback highlights several issues in the test implementation, including the use of an uninitialized project ID variable which results in invalid bucket names, a resource leak due to buckets not being deleted after tests, and redundant variable assignments. Additionally, it is recommended to use null coalescing operators in the samples for better robustness and to include missing filter operator test cases mentioned in the PR description.
| $objectContextsBucket = self::$storage->createBucket( | ||
| sprintf('%s-test-bucket-%s', self::$projectId, time()) | ||
| ); | ||
| $bucketName = $objectContextsBucket->name(); | ||
| $objectName = 'object-contexts-'.uniqid(); | ||
| $object = $objectContextsBucket->upload('test', [ | ||
| 'name' => $objectName, | ||
| ]); | ||
| $objectName = $object->info()['name']; | ||
|
|
||
| // Set Object Contexts | ||
| $setOutput = $this->runFunctionSnippet('set_object_contexts', [ | ||
| $bucketName, | ||
| $objectName, | ||
| ]); | ||
|
|
||
| $this->assertStringContainsString("Contexts for object $objectName were updated", $setOutput); | ||
|
|
||
| // Get Object Contexts | ||
| $getOutput = $this->runFunctionSnippet('get_object_contexts', [ | ||
| $bucketName, | ||
| $objectName | ||
| ]); | ||
|
|
||
| $this->assertStringContainsString('Key: department, Value: finance', $getOutput); | ||
| $this->assertStringContainsString('Key: priority, Value: high', $getOutput); | ||
|
|
||
| // List Object Contexts using filter | ||
| $listOutput = $this->runFunctionSnippet('list_object_contexts', [ | ||
| $bucketName | ||
| ]); | ||
| $this->assertStringContainsString("Found object: $objectName", $listOutput); | ||
|
|
||
| // Clear all contexts on the object. | ||
| $object->update([ | ||
| 'contexts' => [ | ||
| 'custom' => null, | ||
| ], | ||
| ]); | ||
| $object->reload(); | ||
|
|
||
| $clearedGetOutput = $this->runFunctionSnippet('get_object_contexts', [ | ||
| $bucketName, | ||
| $objectName | ||
| ]); | ||
|
|
||
| $this->assertStringNotContainsString('Key: department, Value: finance', $clearedGetOutput); | ||
| $this->assertStringNotContainsString('Key: priority, Value: high', $clearedGetOutput); | ||
|
|
||
| $clearedInfo = $object->info(); | ||
| $this->assertTrue(empty($clearedInfo['contexts']['custom'] ?? [])); | ||
|
|
||
| // List again with filter after clearing contexts. | ||
| $clearedListOutput = $this->runFunctionSnippet('list_object_contexts', [ | ||
| $bucketName | ||
| ]); | ||
| $this->assertEmpty(trim($clearedListOutput)); | ||
| } |
There was a problem hiding this comment.
Yes both object and bucket deleted
…lg-eng/php-docs-samples into feat/sample-object-contexts
nidhiii-27
left a comment
There was a problem hiding this comment.
Added a small comment, rest all LGTM
Uh oh!
There was an error while loading. Please reload this page.